<?php
class PostsController extends AppController {

	public $viewClass = 'Webservice.Webservice';
    // In the component configuration
    public $components = array(
        'Webservice.Webservice' => array(
            'blacklist' => array('home', 'index')
        )
    );
    // As a class property
    public $webserviceBlacklist = array(
        'home', 'index'
    );
    
 	public function index() {    
 		$dataInput = $this->request->input('json_decode');
 		
        $dataOutput = new Object();
        $dataOutput->massage = null;
        $dataOutput->success = true;
        $dataOutput->name = 'nhut';
        $dataOutput->age = 26;
        
        $this->set(compact('dataOutput'));
    }
    public function add() {
    	if ($this->request->is('post')) {
    		// create new Post -- this will grab the file from the request data
    		$newPost = $this->Post->createNew($this->request->data);
    		if ($newPost) {
    			$this->Session->setFlash(__('Your Post has been saved'));
    			// for normal webpage submission
    			if (empty($this->request->params['ext'])) {
    				$this->redirect('/');
    			} else {
    				// for json response to Flex client
    				$result = $newPost;
    				$error = null;
    				$id = null;
    			}
    		} else {
    			$this->Session->setFlash(__('Your Post could not be saved. Please, try again.'));
    			// for json response for failure to create
    			if (!empty($this->request->params['ext'])) {
    				$result = null;
    				$error = 'Your Post could not be saved.';
    				$id = null;
    			}
    		}
    		// this is for json response via Webservice.Webservice
    		$this->set(compact('result', 'error', 'id'));

    	}

    }
}
?>